﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using SharedConfiguration;

namespace install
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        protected LocalConfig _config;
        public MainWindow()
        {
            if(!inicializar())
            {
                this.Close();
            }
            InitializeComponent();
            lbpaso1.ItemsSource = _config.ArqString;
            lbpaso2.ItemsSource = _config.IdiomasString;
        }
       
        protected bool inicializar()
        {
            var ruta = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + @"\";
            if (File.Exists(ruta + "config.json"))
            {
                var config = File.ReadAllText(ruta + "config.json");
                this._config = Newtonsoft.Json.JsonConvert.DeserializeObject<LocalConfig>(config);
                this._config.init();
                return true;

            }
            else
            {
                MessageBox.Show("Error leyendo el archivo de configuración. Asegúrese que el archivo config.json existe en la carpeta. ");
                this.Close();
                return false;
            }
            
        }
    }
}
